package com.taptech.doufu.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.AlbumsBean;
import com.taptech.doufu.bean.MoreNovelCategoryBean;
import com.taptech.doufu.util.StartActivityUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by longsiyang on 16/5/19.
 */
public class MoreNovelShowAdapter extends BaseAdapter
{

    Context mContext;
    List<MoreNovelCategoryBean> listData;

    public MoreNovelShowAdapter(Context mContext, List<MoreNovelCategoryBean> listData)
    {
        this.mContext = mContext;
        if(listData==null){
            listData=new ArrayList<MoreNovelCategoryBean>();
        }
        this.listData = listData;
    }

    @Override
    public int getCount()
    {
        return listData.size();
    }

    @Override
    public Object getItem(int position)
    {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_morenovel, null);
            viewHolder.tvNum = (TextView) convertView.findViewById(R.id.tv_num_morenovel);
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title_morenovel);
            viewHolder.lineContaine=(LinearLayout) convertView.findViewById(R.id.line_item_morenovel);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final MoreNovelCategoryBean bean=listData.get(position);
        if(bean!=null){
            viewHolder.tvNum.setText(bean.getNum()+"部作品");
            viewHolder.tvTitle.setText(bean.getTitle());
            viewHolder.lineContaine.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    //跳转到小说区域去
                    AlbumsBean contentBean=new AlbumsBean();
                    contentBean.setName(bean.getTitle());
                    contentBean.setUrl(bean.getUrl());
                    StartActivityUtil.albumsOnclick(mContext, contentBean);
                }
            });
        }

        return convertView;
    }

    class ViewHolder{
        private TextView tvTitle;
        private TextView tvNum;
        private LinearLayout lineContaine;
    }
}
